package com.hg.oa.module.calendar.layer;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.transition.Slide;
import android.transition.Transition;
import android.view.Gravity;

import com.hg.oa.R;
import com.hg.oa.common.BaseActivityWithToolBar;
import com.hg.oa.module.calendar.model.DayReportInfo;
import com.hg.oa.module.calendar.presenter.CalendarPressenter;

import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by fengxiang on 2016/9/23.
 */
public class DayInfoEditActivity extends BaseActivityWithToolBar {

    String tag = "DayInfoEditActivity";
    Unbinder unbinder;
    CalendarPressenter pressenter;
    int typeFromHomeMenu;
    ApplyDayReportFragment applyDayReportFragment;
    ApplyLevelFragment applyLevelFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_day_edit);
        setBtnLeft1Enable(true);
        typeFromHomeMenu = getIntent().getIntExtra("type", DayInputActivity.TYPE_REPORT);
        pressenter = new CalendarPressenter(this);
        setupWindowAnimations();
        if (typeFromHomeMenu == DayInputActivity.TYPE_REPORT) {
            setTitle("修改日报");
            applyDayReportFragment = pressenter.applyDayReport(R.id.container_day, getSupportFragmentManager().beginTransaction());
        } else if (typeFromHomeMenu == DayInputActivity.TYPE_LEVEL) {
            setTitle("修改请假");
            applyLevelFragment = pressenter.applyLevelReport(R.id.container_day, getSupportFragmentManager().beginTransaction());
        }

        DayReportInfo info = new DayReportInfo();
        info.workItem = "研发";
        info.workDate = "2016-09-22";
        info.workTime = "1.0";
        info.workContent = "HMF功能开发";

        if (applyDayReportFragment != null) {
            Bundle bundle = new Bundle();
            bundle.putSerializable("info", info);
            applyDayReportFragment.setArguments(bundle);
        }
    }

    public static void start(Context context, int type) {
        Intent intent = new Intent(context, DayInfoEditActivity.class);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    @OnClick(R.id.leftBtn1)
    void back() {
        finishAfterTransition();
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private void setupWindowAnimations() {
        Transition transition = buildEnterTransition();
        getWindow().setEnterTransition(transition);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private Transition buildEnterTransition() {
        //侧边滑出
        Slide enterTransition = new Slide();
        enterTransition.setDuration(getResources().getInteger(R.integer.anim_duration_long));
        enterTransition.setSlideEdge(Gravity.RIGHT);
        return enterTransition;
    }

}
